﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.NumericalIntegration
{
    /// <summary>
    /// This class represents an abstract layer for simple integrators.
    /// </summary>
    [Serializable]
    public abstract class AbstractSimpleIntegrator
    {
        /// <summary>
        /// The lower value a of the integral.
        /// </summary>
        private int  a;

        /// <summary>
        /// The upper value b of the integral.
        /// </summary>
        private int b;

        /// <summary>
        /// The polynomial of the integral.
        /// </summary>
        private Polynomial polynomial;

        /// <summary>
        /// The estimated error of the calculated area.
        /// </summary>
        protected double estimatedError;

        /// <summary>
        /// Initializes a new instance of the <see cref="AbstractSimpleIntegrator"/> class.
        /// </summary>
        /// <param name="a">The lower value a of the integral.</param>
        /// <param name="b">The upper value b of the integral.</param>
        /// <param name="polynomial">The polynomial of the integral.</param>
        protected AbstractSimpleIntegrator(int a, int b, Polynomial polynomial)
        {
            this.a = a;
            this.b = b;
            this.polynomial = polynomial;
        }

        /// <summary>
        /// Gets or sets the lower value a of the integral.
        /// </summary>
        /// <value>The lower value a of the integral.</value>
        public int A
        {
            get { return a; }
            set { a = value; }
        }

        /// <summary>
        /// Gets or sets the upper value b of the integral.
        /// </summary>
        /// <value>The upper value b of the integral.</value>
        public int B
        {
            get { return b; }
            set { b = value; }
        }

        /// <summary>
        /// Gets or sets the polynomial of the integral.
        /// </summary>
        /// <value>The polynomial of the integral.</value>
        public Polynomial Polynomial
        {
            get { return polynomial; }
            set { polynomial = value; }
        }

        /// <summary>
        /// Gets a value indicating the size of the absolute error of the result. 
        /// </summary>
        /// <value>A value indicating the size of the absolute error of the result.</value>
        public double EstimatedError
        {
            get { return estimatedError; }
        }

        /// <summary>
        /// Integrates the integral in a numerical way. After running the numerical integration
        /// it should be checked if the result has a precision error.
        /// </summary>
        /// <returns>The area of the specified integral.</returns>
        public abstract double Integrate();
    }
}